package cn.com.yto56.cainiao.exponent.es.controller;

import cn.com.yto56.basic.framework.model.rest.EmptyResponse;
import cn.com.yto56.cainiao.exponent.elasticsearch.service.CommonService;
import cn.com.yto56.cainiao.exponent.elasticsearch.service.TrackService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Slf4j
@RequestMapping("track")
@RestController
public class TrackController {

    @Autowired
    private TrackService trackService;

    @PostMapping("/saveAccuracy/{mailNo}")
    public EmptyResponse saveAccuracyTrack(@PathVariable String mailNo, HttpServletRequest request) throws IOException {
        String json = CommonService.convertInputStream(request.getInputStream());
        trackService.accuracy(mailNo, json);
        return new EmptyResponse();
    }
}
